package com.controller;

import com.entity.Friend;
import com.service.FriendService;
import com.utils.spring.SpringContextUtil;
import com.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import java.util.List;

@RestController
@RequestMapping("/api")
public class FriendController {
	@Autowired
	private FriendService friendService;
	
	@GetMapping("/friend")
	public ResponseVO getAll() {
		List<Friend> result = this.friendService.getAll();
		System.out.println(result);
		ResponseVO responseVO = ResponseVO.generateResponseVO();
		responseVO.setCode("200");
		responseVO.setData(result);
		return responseVO;
	}
	
	/**
	 * 修改好友信息
	 * 修改好友昵称和好友分组
	 *
	 * @param friend 修改的好友信息
	 * @return
	 */
	@PostMapping("/friend/edit")
	public ResponseVO editFriend(@RequestBody Friend friend) {
		return new ResponseVO("200", null, friendService.editFriend(friend));
	}
	
	/**
	 * 删除好友
	 *
	 * @param userId   用户ID
	 * @param friendId 好友ID
	 * @return
	 */
	@PostMapping("/friend/del")
	public ResponseVO delFriend(Integer userId, Integer friendId) {
		return new ResponseVO("200", null, friendService.delFriend(userId, friendId));
	}
}
